import {defineStore} from "pinia";
import {ref} from "vue";
import {getLoginUserUsingGet} from "@/api/userController";


export const useLoginUserStore = defineStore("loginUser", () => {
  // 未登录设置用户名称为‘未登录’
  const loginUser = ref<API.LoginUserVO>({
        userName: "未登录",
    });

    async function fetchLoginUser() {
        const res = await getLoginUserUsingGet();
        if (res.data.code === 0 && res.data.data) {
          loginUser.value = res.data.data;
        }

    }

    function setLoginUser(newLoginUser: any) {
        loginUser.value = newLoginUser;
    }

    return { loginUser, setLoginUser, fetchLoginUser };
})
